package com.seguriapp.gwt.client.gin;

import javax.inject.Singleton;

import net.customware.gwt.dispatch.client.DispatchAsync;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.inject.Provides;
import com.seguriapp.common.gwt.client.SeguriAppSecureDispatchAsync;
import com.seguriapp.gwt.client.PrincipalPage;
import com.seguriapp.gwt.client.PrincipalPagePresenter;
import com.seguriapp.gwt.client.mvp.SeguriAppActivityMapper;
import com.seguriapp.gwt.client.mvp.SeguriAppPlaceHistoryMapper;

public class SeguriAppGinModule extends AbstractGinModule {

  @Override
  protected void configure() {
    bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
    bind(PrincipalPagePresenter.Display.class).to(PrincipalPage.class);
    bind(DispatchAsync.class).to(SeguriAppSecureDispatchAsync.class);
  }

  @SuppressWarnings("deprecation")
  @Provides
  @Singleton
  PlaceController providesPlaceController(final EventBus eventBus) {
    return new PlaceController(eventBus);
  }

  @Provides
  @Singleton
  ActivityManager providesActivityManager(final SeguriAppActivityMapper activityMapper, EventBus eventBus) {
    return new ActivityManager(activityMapper, eventBus);
  }

  @Provides
  @Singleton
  PlaceHistoryHandler providesActivityManager(final SeguriAppPlaceHistoryMapper historyMapper) {
    return new PlaceHistoryHandler(historyMapper);
  }
}
